
package nccloud.bs.arap.txdj.maintain.rule.sendapprove;

import nc.bs.framework.common.NCLocator;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.itf.uap.pf.IPFWorkflowQry;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.arap.amortization.AggAmortizationVO;
import nc.vo.arap.amortization.AmortizationVO;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.wfengine.definition.WorkflowTypeEnum;
import nccloud.arap.util.tool.AllotBillStatus;
import nc.vo.pub.BusinessException;

public class ApproveFlowCheckRule implements IRule<AggAmortizationVO> {
        public void process(AggAmortizationVO[] vos) {
                int vosLength = vos.length;
                for (int i = 0; i < vosLength; ++i) {
            AggAmortizationVO vo = vos[i];
            nc.vo.arap.amortization.AmortizationVO header = vo.getParentVO();
                        if (!isExistWorkflowDefinition("TXDJ", header.getPk_org(),
                                        header.getCreator(), WorkflowTypeEnum.Approveflow.getIntValue())) {
                                ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4009001_0", "04009001-0039"));
                        }

                        if (!AllotBillStatus.FREE.value().equals(header.getApprovestatus())) {
                                ExceptionUtils.wrappBusinessException(
                                                NCLangRes4VoTransl.getNCLangRes().getStrByID("4009012_0", "04009012-0041"));
                        }
                }

        }
        
        private boolean isExistWorkflowDefinition(String billOrTranstype,
                      String pkOrg, String operator, int iWorkflowOrApproveflow) {
                try {
                      return NCLocator
                          .getInstance()
                          .lookup(IPFWorkflowQry.class)
                          .isExistWorkflowDefinition(billOrTranstype, pkOrg, operator,
                              iWorkflowOrApproveflow);
                    }
                    catch (BusinessException e) {
              // 日志异常
                      ExceptionUtils.wrappException(e);
                    }
                    return false;
        }
}
